import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../environments/environment';

@Component({
    selector: 'app-root',
    template: `
        hello
        <br>
        <button (click)="load()">点击访问后台</button>
        <br>
        {{message}}
    `,
    styles: [],
})
export class AppComponent implements OnInit {
    message: any;

    constructor(
        private http: HttpClient,
    ) {
    }

    ngOnInit(): void {
        this.load();
    }

    load() {
        this.http.get(`${BASE_URL}/api/test`, {responseType: 'text'}).subscribe(r => {
            console.log('r', r);
            this.message = r;
        });
    }
}

export const BASE_URL = `${environment.production ? 'http://localhost:8080' : ''}`;
